package com.qc.blogsystemplus.service;

import com.qc.blogsystemplus.bean.DiscussBean;
import com.qc.blogsystemplus.entity.Discuss;
import com.qc.blogsystemplus.mapper.DiscussMapper;
import com.qc.blogsystemplus.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiscussService {

    @Autowired
    private DiscussMapper discussMapper;

    @Autowired
    private UserMapper userMapper;

    public List<Discuss> getDiscuss(int article_id) {
        List<Discuss> list =  discussMapper.getDiscuss(article_id);
        return list;
    }

    public int addDiscuss(Discuss discuss) {
        DiscussBean discussBean = new DiscussBean();
        int userid = userMapper.getUser(discuss.getUsername()).getId();

        discussBean.setUser_id(userid);
        discussBean.setArticle_id(discuss.getArticle_id());
        discussBean.setContent(discuss.getContent());
        return discussMapper.addDiscuss(discussBean);
    }

    public int delDiscuss(int id){
        DiscussBean discussBean = new DiscussBean();
        discussBean.setId(id);
        int re = discussMapper.delDeiscuss(discussBean);
        return re;
    }

    public List<Discuss> getAllDiscuss (){
        return discussMapper.getAllDiscuss();
    }
}
